<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>04</title>
</head>
<body>
    <div :[key]="color" id="root">
        <span v-if="color == 'red'" @click="handleClick">红色</span>
        <span v-if="color == 'green'">绿色</span>
    </div>
</body>
<!-- 开发环境版本，包含了有帮助的命令行警告 -->
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<script>
    var vm = new Vue({
        el: '#root',
        data: {
            color: 'red',
            key: 'Class',
        },
        methods: {
            handleClick: function() {
                this.color = 'green';
            },
        },
    });

    setTimeout(function() {vm.info='2秒过去了'}, 2000);
</script>
<style>
    .red {
        color: red;
    }
    .green {
        color: green;
    }
</style>
</html>